home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / PRINT.C < prev    next >
Text File  |  1987-06-18  |  3KB  |  134 lines

  1.  
  2. /* ---------------------------------------------------    */
  3. /*    PRINT - Print a file with header to the printer    */
  4. /*        M. Burton    04 July 1983        */
  5. /*    Written in Computer Innovations C86        */
  6. /* ---------------------------------------------------    */
  7. /*        Syntax:                    */
  8. /*                            */
  9. /*    PRINT filename.typ - Print a file with line    */
  10. /*                numbers.        */
  11. /*    PRINT filename.typ /N - Print a file without    */
  12. /*                line numbers.        */
  13. /* ---------------------------------------------------    */
  14.  
  15. #include "stdio.h"
  16.  
  17. struct regval        /* Register structure for INT    */
  18. {
  19.     int ax,bx,cx,dx,si,di,ds,es;
  20. }
  21. struct regval srv, rrv, trv, brv;
  22. int mo, dy, yr;
  23. int hr, mn, sc, hn;
  24.  
  25. main(argc,argv)
  26.     int argc;    /* Number of args in cmd line    */
  27.     char *argv[];    /* Args in cmd line        */
  28. {
  29.     int *fd;    /* File stream pointer        */
  30.     int *cd;    /* Printer stream pointer    */
  31.     char *sp;    /* filename.typ pointer        */
  32.     int c;        /* Loop variable        */
  33.     int lineno=1;    /* Line counter            */
  34.     int pline=1;    /* Line on page counter        */
  35.     int page=1;    /* Page counter            */
  36.     char s[232];    /* Line buffer            */
  37.  
  38.     srv.ax = (0x2c << 8);
  39.     sysint(0x21,&srv,&brv); /* Get the time        */
  40.  
  41.     if (argc == 1)
  42.     {
  43.         printf("Proper syntax: PRINT filename.typ </N>\007\n");
  44.         goto abort;
  45.     }
  46.  
  47.     sp = argv[1];
  48.     while ((*sp = toupper(*sp)) != EOS) sp++;
  49.     fd = fopen(argv[1],"r");
  50.     if (fd == 0)
  51.     {
  52.         printf("%s not found\007\n",argv[1]);
  53.         goto abort;
  54.     }
  55.  
  56.     cd = fopen("PRN:","w");
  57.     if (cd == 0)
  58.     {
  59.         printf("Printer offline\007\n");
  60.         goto abort;
  61.     }
  62.  
  63.     c = 1;
  64.     prthdr(page,cd,argv[1]);
  65.     while (c != EOS)
  66.     {
  67.         pline = 1;
  68.         while (pline < 57)
  69.         {
  70.             c = fgets(s,232,fd);
  71.             if (c == EOS) goto quit;
  72.             if (argc == 3)
  73.             {
  74.                 if (strncmp(argv[2],"/n",2) == 0 || strncmp(argv[2],"/N",2) == 0)
  75.                 {
  76.                     fprintf(cd,"%s",s);
  77.                 }
  78.             }
  79.             else
  80.             {
  81.                 fprintf(cd,"%7u  %s",lineno,s);
  82.             }
  83.             lineno++;
  84.             pline++;
  85.         }
  86.         page++;
  87.         fprintf(cd,"\n\014");
  88.         prthdr(page,cd,argv[1]);
  89.     }
  90. quit:
  91.     fprintf(cd,"  \n\014");
  92.     srv.ax = (0x2c << 8);
  93.     sysint(0x21,&srv,&trv);        /* Get end time    */
  94.     hr = (trv.cx >> 8) - (brv.cx >> 8);
  95.     if((mn = (trv.cx & 0xff) - (brv.cx & 0xff)) < 0)
  96.     {
  97.         hr--;
  98.         mn = mn + 60;
  99.     }
  100.     if((sc = (trv.dx >> 8) - (brv.dx >> 8)) < 0)
  101.     {
  102.         mn--;
  103.         sc = sc + 60;
  104.         if (mn < 0)
  105.         {
  106.             hr--;
  107.             mn = mn + 60;
  108.         }
  109.     }
  110.     printf("Finished printing '%s';",argv[1]);
  111.     printf("%5u lines,%5u pages.\n",--lineno,page);
  112.     printf("Total print time %02u:%02u:%02u\n",hr,mn,sc);
  113.     fclose(fd);
  114.     fclose(cd);
  115. abort:    ;        /* Dummy line            */
  116. }
  117.  
  118. prthdr(p,cc,aa)        /* Print the page header    */
  119.     int p, cc, *aa;
  120. {
  121.     srv.ax = (0x2a << 8);
  122.     sysint(0x21,&srv,&rrv);
  123.     mo = (rrv.dx >> 8);
  124.     dy = (rrv.dx & 0xff);
  125.     yr = rrv.cx;
  126.     srv.ax = (0x2c << 8);
  127.     sysint(0x21,&srv,&trv);
  128.     hr = (trv.cx >> 8);
  129.     mn = (trv.cx & 0xff);
  130.     sc = (trv.dx >> 8);
  131.     hn = (trv.dx & 0xff);
  132.     fprintf(cc,"Listing of %s     %02u-%02u-%4u     %02u:%02u:%02u.%02u                   Page %3u\n",aa,mo,dy,yr,hr,mn,sc,hn,p);
  133. }
  134.